#include "../include/cmd.h"

int puts_filename_command(int clientfd, cmd_t *cmd){
    //打开要发送文件
    // 参数个数不为 1 直接返回
    char clientfilename[66]={0};
    strcpy(clientfilename,cmd->args[0].arg);
    
    char filename[100]={0};
    sprintf(filename,"/home/kingyu/cloud_disk/%s",clientfilename);

    int fd = open(filename, O_RDWR | O_CREAT |O_TRUNC, 0777);
    ssize_t filesize = 0;
    recv(clientfd, &filesize, 8, MSG_WAITALL);
    printf("recvfilesize =%ld\n",filesize);

    ftruncate(fd,filesize);
        
    char* pbuf=(char*)mmap(NULL,filesize,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);

    recv(clientfd,pbuf,filesize,MSG_WAITALL);

    munmap(pbuf,filesize);

    return 1;
}
